package com.job.meituan;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @ClassName: test.Meituan2
 * @Description:
 * @Author: 12071
 * @Date: 2022/4/9 16:56
 */
public class Meituan0409_2 {
    static class Person{
        int high;
        String name;
        public Person(int high, String name){
            this.high = high;
            this.name = name;
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] highs = new int[n];
        for(int i=0;i<n;i++)
            highs[i] = sc.nextInt();
        sc.nextLine();
        String[] names=sc.nextLine().split(" ");
        Person[] persons = new Person[n];
        for(int i=0;i<n;i++){
            persons[i] = new Person(highs[i],names[i]);
        }
        Arrays.sort(persons, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                if(o1.high!=o2.high) return o1.high-o2.high;
                    String name1=o1.name;
                    String name2=o2.name;
                    for (int i = 0; i < name1.length() || i<name2.length(); i++) {
                        char ch1 = i<name1.length()?name1.charAt(i):'a'-1;
                        char ch2 = i<name2.length()?name2.charAt(i):'a'-1;
                        if(ch1!=ch2) return ch1-ch2;
                    }
                return 0;
            }
        });
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<n;i++){
            sb.append(persons[i].name+" ");
        }
        System.out.println(sb.toString().trim());
    }
}
